package com.ttdevs.es;

import android.os.Bundle;
import android.os.Message;
import android.view.View;

import com.ttdevs.BaseActivity;
import com.ttdevs.util.StaticConstants;

public class StartActivity extends BaseActivity implements StaticConstants {

	private StartHandler handler;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_start);
		
		handler = new StartHandler(StartActivity.this,getApplicationContext());
	}

	public void onClick(View view) {
		if (view.getId() == R.id.btStart) {
			Message msg = handler.obtainMessage();
			if (!checkTriggerWay()) {
				msg.what = ERROR;
				msg.obj = "未选择触发方式";
				handler.sendMessage(msg);
				return;
			}
			if (!checkAlarmWay()) {
				 msg.what = ERROR;
				 msg.obj = "未选择报警方式";
				 handler.sendMessage(msg);
				 return;
			}
			msg.what = PASS;
			handler.sendMessage(msg);
		}
	}

	private boolean checkAlarmWay() {
		return spUtil.getRing() || spUtil.getVibrate();
	}

	private boolean checkTriggerWay() {
		return spUtil.getHeadSet() || spUtil.getLight() || spUtil.getProximity() || spUtil.getSMS() || spUtil.getUSB();
	}
}